<template>
  <div>
    <div class="content">
      <div class="formBox">
        <h3>运动潮牌论坛登录</h3>
        <div class="inputItem" style="margin-top: 20px">
          <input type="text" placeholder="账号" v-model="youxiang" />
        </div>
        <div class="inputItem">
          <input
            type="password"
            placeholder="密码"
            v-model="password"
            maxlength="16"
          />
        </div>
        <div class="inputItem_radio">
          <div class="zhuce" @click="zhuce">注册账户</div>
          <span class="forget" @click="forget">忘记密码</span>
        </div>
        <div class="submit" @click="sumbit">登录</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  components: {},
  data: function () {
    return {
      youxiang: "",
      password: "",
    };
  },
  methods: {
    async sumbit() {
      const data = {
        username: this.youxiang,
        password: this.password,
      };
      let result = await this.$request.reqlogin(data);
      if (result.code == 200) {
        localStorage.setItem("token", result.token);
        this.getUserId()
        this.$router.push("/");
        this.$message.success("登录成功");
      }else{
        this.$message.error(result.msg);
      }
    },
    async getUserId() {
        // 获取用户信息
        let rel = await this.$request.reqgetInfo();
      if (rel.code == 200) {
        // 存储获取用户信息Id
        console.log(rel,'cnm');
        localStorage.setItem("USERID", rel.user.userId);
        localStorage.setItem("username", rel.user.userName);
      }
    },
    zhuce() {
      this.$router.push('/registered');
    },
    forget() {
      this.$router.push('/forget');
    },
  },
};
</script>

<style scoped>
.content {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 200px;
  color: rgb(255, 255, 255);
}

.formBox {
  width: 390px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.inputItem {
  margin-bottom: 18px;
  position: relative;
}

.inputItem input {
  width: 293px;
  height: 42px;
  border-radius: 2px;
  opacity: 1;
  border: 1px solid rgba(221, 221, 221, 1);
  background: rgba(242, 247, 244, 1);
  padding-left: 12px;
  outline: none;
}

.zhuce {
  color: #ff8b1a;
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
  /* 变成手 */
}

.inputItem__slotFix {
  display: flex;
  justify-content: center;
  align-items: center;
}

.submit {
  width: 293px;
  height: 42px;
  border-radius: 2px;
  opacity: 1;
  background: #ff8b1a;
  color: rgba(255, 255, 255, 1);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  line-height: 42px;
  cursor: pointer;
  /* 变成手 */
}

.radioIcon {
  width: 18px;
  height: 18px;
}

.inputItem_radio {
  width: 293px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.radioBox {
  display: flex;
  align-items: center;
  cursor: pointer;
  /* 变成手 */
}

.forget {
  font-size: 14px;
  color: #999999;
  cursor: pointer;
  /* 变成手 */
}
</style>